home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-201-c / sfx ƒ / sfx control app ƒ / Shell ƒ / about.c < prev    next >
Text File  |  1994-07-11  |  6KB  |  216 lines

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "about.h"
  25. #include "prefs.h"
  26. #include "util.h"
  27. #include "pixel dissolve.h"
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for about.c                                                        */
  31.  
  32. static void SetupTheAboutBox(WindowDataHandle theData);
  33. static void InitializeTheAboutBox(WindowDataHandle theData);
  34. static void OpenTheAboutBox(WindowDataHandle theData);
  35. static void ResizeTheAboutBox(WindowDataHandle theData);
  36. static void ShutdownTheAboutBox(WindowDataHandle theData);
  37. static void DrawTheAboutBox(Boolean isColor);
  38. static void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  39. static void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  40.  
  41. Boolean            gUseAlternate;
  42. Boolean            gUseDissolve;
  43.  
  44. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  45. {
  46.     short            theDepth;
  47.     
  48.     switch (theMessage)    /* see graphics.h for list of messages*/
  49.     {
  50.         case kKeydown:                            /* close about box on keypress */
  51.         case kMousedown:                        /* or mouseclick */
  52.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  53.             return kSuccess;
  54.             break;
  55.         case kUpdate:
  56.             theDepth=misc&0x7fff;                /* pixel depth */
  57.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  58.             return kSuccess;
  59.             break;
  60.         case kInitialize:
  61.             InitializeTheAboutBox(theData);
  62.             return kFailure;
  63.         case kOpen:
  64.             OpenTheAboutBox(theData);
  65.             return kSuccess;
  66.             break;
  67.         case kStartup:
  68.             SetupTheAboutBox(theData);
  69.             return kSuccess;
  70.             break;
  71.         case kShutdown:
  72.             ShutdownTheAboutBox(theData);
  73.             return kSuccess;
  74.             break;
  75.         case kCopybits:
  76.             if (gUseDissolve)
  77.             {
  78.                 PixelDissolve(GetOffscreenGrafPtr(theData), GetWindowGrafPtr(theData),
  79.                     GetWindowGrafPtr(theData)->portRect);
  80.                 gUseDissolve=FALSE;
  81.                 return kSuccess;
  82.             }
  83.             break;
  84.     }
  85.     
  86.     return kFailure;        /* for all other messages, defer to default processing */
  87. }
  88.  
  89. void SetupTheAboutBox(WindowDataHandle theData)
  90. {
  91.     unsigned char    *theTitle="\pShutdown FX";
  92.     
  93.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  94.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  95.     (**theData).hasCloseBox=TRUE;
  96.     (**theData).maxDepth=1;
  97.     gUseAlternate=gUseDissolve=FALSE;
  98. }
  99.  
  100. void InitializeTheAboutBox(WindowDataHandle theData)
  101. {
  102.     (**theData).windowWidth=170;
  103.     (**theData).windowHeight=158;
  104. }
  105.  
  106. void OpenTheAboutBox(WindowDataHandle theData)
  107. {
  108.     KeyMap            rawKeys;
  109.     unsigned short    theKeys[8];
  110.     
  111.     ShowWindow(GetWindowGrafPtr(theData));
  112.     SelectWindow(GetWindowGrafPtr(theData));
  113.     GetKeys(rawKeys);
  114.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  115.     if (theKeys[3]&4)    /* option key down? */
  116.     {
  117.         if (!gUseAlternate)
  118.         {
  119.             gUseAlternate=TRUE;
  120.             (**theData).offscreenNeedsUpdate=TRUE;
  121.         }
  122.     }
  123.     else
  124.     {
  125.         if (gUseAlternate)
  126.         {
  127.             gUseAlternate=FALSE;
  128.             (**theData).offscreenNeedsUpdate=TRUE;
  129.         }
  130.     }
  131.     if (theKeys[3]&32768)
  132.     {
  133.         gUseDissolve=TRUE;
  134.         (**theData).offscreenNeedsUpdate=TRUE;
  135.     }
  136.     if ((**theData).offscreenNeedsUpdate)
  137.         UpdateTheWindow(theData);
  138. }
  139.  
  140. void ShutdownTheAboutBox(WindowDataHandle theData)
  141. {
  142. }
  143.  
  144. void DrawTheAboutBox(Boolean isColor)
  145. {
  146.     RGBColor        oldForeColor, oldBackColor;
  147.     short            row;
  148.     Handle            textHandle;
  149.     Str255            theLine;
  150.     unsigned long    pos;
  151.     unsigned long    theSize;
  152.     GrafPtr            curPort;
  153.     short            theCenter;
  154.     RGBColor        myGray={49152, 49152, 49152};
  155.     
  156.     GetPort(&curPort);
  157.     if (isColor)
  158.     {
  159.         GetForeColor(&oldForeColor);
  160.         GetBackColor(&oldBackColor);
  161.         RGBForeColor(&myGray);
  162.         PaintRect(&(curPort->portRect));
  163.         RGBForeColor(&oldForeColor);
  164.         RGBBackColor(&oldBackColor);
  165.         TextMode(srcOr);
  166.     }
  167.     else
  168.     {
  169.         FillRect(&(curPort->portRect), black);
  170.         TextMode(srcXor);
  171.     }
  172.     
  173.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  174.     
  175.     TextFont(geneva);
  176.     TextSize(9);
  177.     row=16;
  178.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  179.     if (textHandle==0L)
  180.         return;
  181.     if (*textHandle==0L)
  182.         LoadResource(textHandle);
  183.     if (*textHandle==0L)
  184.         return;
  185.     pos=0L;
  186.     theSize=SizeResource(textHandle);
  187.     do
  188.     {
  189.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  190.         DrawTheAboutString(theLine, &row, theCenter);
  191.     }
  192.     while (pos<theSize);
  193.     ReleaseResource(textHandle);
  194.     if (isColor)
  195.         ForeColor(blackColor);
  196.     TextMode(srcCopy);
  197.     TextSize(12);
  198.     TextFont(0);
  199. }
  200.  
  201. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  202. {
  203.     unsigned char    theChar;
  204.     
  205.     theLine[0]=0x00;
  206.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  207.         theLine[++theLine[0]]=theChar;
  208. }
  209.  
  210. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  211. {
  212.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  213.     DrawString(theString);
  214.     *theRow+=12;
  215. }
  216.